<?php
namespace app\common\library\notice;
use EasyWeChat\Factory;
/**
 * 微信公众号的模板消息
 *
 * @author LCY <409028735@qq.com>
 */
class WechatTemplate{

    /**
     * 发送公众号模板消息
     *
     * @param array $params 消息参数
     * @return true|string true:表示发送成功
     */
    public static function send($params= []){
        try{
            $config = config('wechat.mp');
        
            $app = Factory::officialAccount($config);
            $app->template_message->send([
                'touser' => $params['openid'],
                'template_id' => $params['template_id'],
                'url' => 'https://easywechat.com',
                'miniprogram' => [
                        'appid' => 'xxxxxxx',
                        'pagepath' => 'pages/xxx',
                ],
                'data' => [
                    'key1' => 'VALUE',
                    'key2' => 'VALUE2'
                ],
            ]);

            return true;
        }catch(\Exception $e){
            recordExceptionInfo($e);
            return $e->getMessage();
        }
        
    }
    

}